package sctu.edu.java.year2016.team01.OurTeamProject.subroutine;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;

/**
 * Created by Zero on 2016/6/27.
 */
public class FunctionList {

    public void functionList(){


        Read read=new Read();
        RegisterSuccess rs=new RegisterSuccess();
        String path="src\\main\\java\\sctu\\edu\\java\\year2016\\team01\\OurTeamProject";
        JFrame f = new JFrame();
        f.setLayout(null);
        f.setTitle("功能列表");
        f.setBounds(800, 300, 800, 600);
        Container con = f.getContentPane();
        JPanel pan = new JPanel();

        JLabel title=new JLabel("问题选项:");
        title.setFont(new Font("宋体", Font.BOLD, 21));
        title.setForeground(Color.white);
        title.setBounds(150, 200, 100, 40);




        ImageIcon background=new ImageIcon(path+"\\背景.png");
        JLabel label=new JLabel(background);
        label.setBounds(0, 0, 800, 600);
        JPanel imagePanel = (JPanel) f.getContentPane();
        imagePanel.setOpaque(false);
        f.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));


        JButton problem1=new JButton("A.蓝屏");
        problem1.setFont(new Font("宋体", Font.BOLD, 19));
        problem1.setContentAreaFilled(false);
        problem1.setForeground(Color.white);
        problem1.setBounds(150, 250, 140, 30);

        JButton problem2=new JButton("B.无法上网");
        problem2.setFont(new Font("宋体", Font.BOLD, 19));
        problem2.setContentAreaFilled(false);
        problem2.setForeground(Color.white);
        problem2.setBounds(150, 290, 140, 30);

        JButton problem3=new JButton("C.电脑卡顿");
        problem3.setFont(new Font("宋体", Font.BOLD, 19));
        problem3.setContentAreaFilled(false);
        problem3.setForeground(Color.white);
        problem3.setBounds(150, 330, 140, 30);

        JButton problem4=new JButton("D.其他");
        problem4.setFont(new Font("宋体", Font.BOLD, 19));
        problem4.setContentAreaFilled(false);
        problem4.setForeground(Color.white);
        problem4.setBounds(150, 370, 140, 30);




        problem1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {


                File file = new File("D:/problem1.txt");
                if (!file.exists()) {
                    try {
                        file.createNewFile();
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }


                try {

                    FileReader fr = new FileReader(file);
                    if ((fr.read() == -1)) {

                        rs.noSolution();

                    } else {


                        JFrame f = new JFrame();
                        f.setLayout(null);
                        f.setTitle("解决方案");
                        f.setBounds(800, 300, 800, 600);
                        Container con = f.getContentPane();
                        JPanel pan = new JPanel();

                        ImageIcon background = new ImageIcon(path + "\\背景.png");
                        JLabel label = new JLabel(background);
                        label.setBounds(0, 0, 800, 600);
                        JPanel imagePanel = (JPanel) f.getContentPane();
                        imagePanel.setOpaque(false);
                        f.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));

                        JLabel title = new JLabel("解决方案:");
                        title.setFont(new Font("宋体", Font.BOLD, 21));
                        title.setForeground(Color.white);
                        f.getContentPane().add(title);
                        title.setBounds(100, 50, 150, 40);

                        JTextArea solutionContent = new JTextArea(10, 30);
                        JScrollPane jsp = new JScrollPane(solutionContent);
                        solutionContent.setBounds(100, 100, 400, 300);
                        solutionContent.setFont(new Font("宋体", Font.BOLD, 21));
                        solutionContent.setLineWrap(true);
                        f.getContentPane().add(solutionContent);
                        f.getContentPane().add(jsp);
                        jsp.setBounds(100, 100, 400, 300);
                        con.add(pan);
                        f.setVisible(true);
                        f.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
                        solutionContent.setText(read.readToString("D:/problem1.txt"));

                    }
                } catch (Exception e1) {
                    e1.printStackTrace();
                }

                f.dispose();

            }
        });


        problem2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {


                File file = new File("D:/problem2.txt");
                if (!file.exists()) {
                    try {
                        file.createNewFile();
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }


                try {

                    FileReader fr = new FileReader(file);
                    if ((fr.read() == -1)) {

                        rs.noSolution();

                    } else {

                        JFrame f = new JFrame();
                        f.setLayout(null);
                        f.setTitle("解决方案");
                        f.setBounds(800, 300, 800, 600);
                        Container con = f.getContentPane();
                        JPanel pan = new JPanel();

                        ImageIcon background = new ImageIcon(path + "\\背景.png");
                        JLabel label = new JLabel(background);
                        label.setBounds(0, 0, 800, 600);
                        JPanel imagePanel = (JPanel) f.getContentPane();
                        imagePanel.setOpaque(false);
                        f.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));

                        JLabel title = new JLabel("解决方案:");
                        title.setFont(new Font("宋体", Font.BOLD, 21));
                        title.setForeground(Color.white);
                        f.getContentPane().add(title);
                        title.setBounds(100, 50, 150, 40);

                        JTextArea solutionContent = new JTextArea(10, 30);
                        JScrollPane jsp = new JScrollPane(solutionContent);
                        solutionContent.setBounds(100, 100, 400, 300);
                        solutionContent.setFont(new Font("宋体", Font.BOLD, 21));
                        solutionContent.setLineWrap(true);
                        f.getContentPane().add(solutionContent);
                        f.getContentPane().add(jsp);
                        jsp.setBounds(100, 100, 400, 300);
                        con.add(pan);
                        f.setVisible(true);
                        f.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
                        solutionContent.setText(read.readToString("D:/problem2.txt"));


                    }

                } catch (Exception e1) {
                    e1.printStackTrace();
                }

                f.dispose();

            }
        });


        problem3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {


                File file = new File("D:/problem3.txt");
                if (!file.exists()) {
                    try {
                        file.createNewFile();
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }


                try {

                    FileReader fr = new FileReader(file);
                    if ((fr.read() == -1)) {

                        rs.noSolution();

                    } else {

                        JFrame f = new JFrame();
                        f.setLayout(null);
                        f.setTitle("解决方案");
                        f.setBounds(800, 300, 800, 600);
                        Container con = f.getContentPane();
                        JPanel pan = new JPanel();

                        ImageIcon background = new ImageIcon(path + "\\背景.png");
                        JLabel label = new JLabel(background);
                        label.setBounds(0, 0, 800, 600);
                        JPanel imagePanel = (JPanel) f.getContentPane();
                        imagePanel.setOpaque(false);
                        f.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));

                        JLabel title = new JLabel("解决方案:");
                        title.setFont(new Font("宋体", Font.BOLD, 21));
                        title.setForeground(Color.white);
                        f.getContentPane().add(title);
                        title.setBounds(100, 50, 150, 40);

                        JTextArea solutionContent = new JTextArea(10, 30);
                        JScrollPane jsp = new JScrollPane(solutionContent);
                        solutionContent.setBounds(100, 100, 400, 300);
                        solutionContent.setFont(new Font("宋体", Font.BOLD, 21));
                        solutionContent.setLineWrap(true);
                        f.getContentPane().add(solutionContent);
                        f.getContentPane().add(jsp);
                        jsp.setBounds(100, 100, 400, 300);
                        con.add(pan);
                        f.setVisible(true);
                        f.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
                        solutionContent.setText(read.readToString("D:/problem3.txt"));


                    }

                } catch (Exception e1) {
                    e1.printStackTrace();
                }

                f.dispose();

            }
        });


        problem4.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {


                File file = new File("D:/problem4.txt");
                if (!file.exists()) {
                    try {
                        file.createNewFile();
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }


                try {

                    FileReader fr = new FileReader(file);
                    if ((fr.read() == -1)) {

                        rs.noSolution();

                    } else {

                        JFrame f = new JFrame();
                        f.setLayout(null);
                        f.setTitle("解决方案");
                        f.setBounds(800, 300, 800, 600);
                        Container con = f.getContentPane();
                        JPanel pan = new JPanel();

                        ImageIcon background = new ImageIcon(path + "\\背景.png");
                        JLabel label = new JLabel(background);
                        label.setBounds(0, 0, 800, 600);
                        JPanel imagePanel = (JPanel) f.getContentPane();
                        imagePanel.setOpaque(false);
                        f.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));

                        JLabel title = new JLabel("解决方案:");
                        title.setFont(new Font("宋体", Font.BOLD, 21));
                        title.setForeground(Color.white);
                        f.getContentPane().add(title);
                        title.setBounds(100, 50, 150, 40);

                        JTextArea solutionContent = new JTextArea(10, 30);
                        JScrollPane jsp = new JScrollPane(solutionContent);
                        solutionContent.setBounds(100, 100, 400, 300);
                        solutionContent.setFont(new Font("宋体", Font.BOLD, 21));
                        solutionContent.setLineWrap(true);
                        f.getContentPane().add(solutionContent);
                        f.getContentPane().add(jsp);
                        jsp.setBounds(100, 100, 400, 300);
                        con.add(pan);
                        f.setVisible(true);
                        f.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
                        solutionContent.setText(read.readToString("D:/problem4.txt"));


                    }

                } catch (Exception e1) {
                    e1.printStackTrace();
                }

                f.dispose();

            }
        });



        f.getContentPane().add(title);
        f.getContentPane().add(problem1);
        f.getContentPane().add(problem2);
        f.getContentPane().add(problem3);
        f.getContentPane().add(problem4);
        f.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
        con.add(pan);
        f.setVisible(true);
    }
}




